package com.zmn.oms.business.impl.callinfo;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.alibaba.nacos.api.config.annotation.NacosValue;
import com.google.api.client.util.Lists;
import com.google.common.collect.Maps;
import com.zmn.base.channel.common.dro.ChannelDRO;
import com.zmn.base.channel.dubbo.interfaces.channel.ChannelListRemoteService;
import com.zmn.base.common.data.common.dro.area.AreaDRO;
import com.zmn.base.common.data.dubbo.interfaces.area.AreaListRemoteService;
import com.zmn.base.product.common.dto.product.ProductBaseQuery;
import com.zmn.base.product.common.dto.product.ec.ProductBaseDRO;
import com.zmn.base.product.dubbo.interfaces.product.foreign.ProductForeignListRemoteService;
import com.zmn.base.remind.common.consts.MqConst;
import com.zmn.base.remind.common.enums.AppTypeEnum;
import com.zmn.base.remind.common.enums.ScenesTypeEnum;
import com.zmn.base.remind.common.model.remind.RemindRequestDIO;
import com.zmn.base.remind.common.model.remind.VoiceVariateDIO;
import com.zmn.common.constant.GlobalConsts;
import com.zmn.common.constant.StatusConsts;
import com.zmn.common.dto2.ResponseDTO;
import com.zmn.common.utils.MethodSignUtils;
import com.zmn.common.utils.collection.CollectionUtil;
import com.zmn.common.utils.date.DateUtil;
import com.zmn.common.utils.number.NumberUtil;
import com.zmn.common.utils.string.StringUtil;
import com.zmn.manager.common.cat.http.MonitorHttpsUtils;
import com.zmn.manager.mq.interfaces.ZmnMQSender;
import com.zmn.mcc.cas.model.LoginStaff;
import com.zmn.mcc.cas.web.StaffAdminService;
import com.zmn.oms.business.interfaces.callinfo.CallInfoBService;
import com.zmn.oms.business.interfaces.work.OrderWorkListBService;
import com.zmn.oms.common.annotation.ZsNormalOrderWorkLog;
import com.zmn.oms.common.constant.CallCenterConstant;
import com.zmn.oms.common.constant.OrderConsts;
import com.zmn.oms.common.constant.OrderLogConsts;
import com.zmn.oms.common.dto.ResultDTO;
import com.zmn.oms.common.exception.OmsBaseException;
import com.zmn.oms.constant.MessageQueueTopicConstant;
import com.zmn.oms.model.dto.call.CallInfoDTO;
import com.zmn.oms.model.dto.work.call.CallOutDTO;
import com.zmn.oms.model.entity.callinfo.CallAddInfo;
import com.zmn.oms.model.entity.callinfo.CallClueInfo;
import com.zmn.oms.model.entity.callinfo.CallInfo;
import com.zmn.oms.model.entity.detail.OrderDetail;
import com.zmn.oms.model.entity.master.OrderMaster;
import com.zmn.oms.model.entity.product.OrderProduct;
import com.zmn.oms.model.entity.work.OrderWork;
import com.zmn.oms.model.entity.work.OrderWorkQuery;
import com.zmn.oms.services.interfaces.detail.OrderDetailService;
import com.zmn.oms.services.interfaces.master.OrderMasterService;
import com.zmn.oms.services.interfaces.product.OrderProductService;
import com.zmn.oms.services.interfaces.work.OrderWorkService;
import com.zmn.track.common.utils.SignUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.*;


/**
 * 类描述：呼叫信息录入
 *
 * @author yule
 * @date 2019/07/01 16:35
 */
@Service
@Slf4j
public class CallInfoBServiceImpl implements CallInfoBService {

    /**
     * 呼叫信息录入地址
     */
    private static String CALL_INFO_OLD_URL = "http://dev-cc.xiujiadian.com/open/information/center/add";
    @NacosValue(value="${call.order.add.url:http://dev-cc.xiujiadian.com/open/information/center/add}", autoRefreshed = true)
    public void setCallInfoOldUrl(String url) {
        CALL_INFO_OLD_URL = url;
    }

    private static String CALL_INFO_URL = "http://dev-gateway-api.xiujiadian.com/ccc/api/clue/addClue";
    @NacosValue(value="${call.order.add.clue.url:http://dev-gateway-api.xiujiadian.com/ccc/api/clue/addClue}", autoRefreshed = true)
    public void setCallInfoUrl(String url) {
        CALL_INFO_URL = url;
    }

    /**
     * 呼叫催单地址
     */
    private static String CALL_REMIND_URL = "http://test2-remind-api.xiujiadian.com/remind/launch";
    @NacosValue(value="${call.remind.url:http://test2-remind-api.xiujiadian.com/remind/launch}", autoRefreshed = true)
    public void setCallRemindUrl(String url) {
        CALL_REMIND_URL = url;
    }

    @NacosValue(value="${call.order.add.useNewInterface:false}", autoRefreshed = true)
    private Boolean useNewInterface = false;

    /**
     * 使用新呼叫催单
     */
    @NacosValue(value = "${call.order.remind.useNewRemind:false}", autoRefreshed = true)
    private Boolean useNewRemind = false;

    /**
     * 呼叫线索信息录入地址
     */
    private static String CALL_CLUE_URL = "http://test2-cc.xiujiadian.com/open/information/center/add/oms";
    @NacosValue(value="${call.clue.add.url:http://test2-cc.xiujiadian.com/open/information/center/add/oms}", autoRefreshed = true)
    public void setCallClueUrl(String url) {
        CALL_CLUE_URL = url;
    }

    /**
     * 呼叫系统密钥
     */
    private static String SIGN_KEY = "867D0B5FBEBFEF9818DF9F39E87EAA9E";
    @NacosValue(value="${call.info.sign.key:867D0B5FBEBFEF9818DF9F39E87EAA9E}", autoRefreshed = true)
    public void setSignKey(String signKey) {
        SIGN_KEY = signKey;
    }


    @Reference(version = com.zmn.base.plat.engine.common.constant.DubboConsts.INTERFACE_VERSION , check = false)
    private AreaListRemoteService areaListRemoteService;
    @Reference(version = com.zmn.base.plat.engine.common.constant.DubboConsts.INTERFACE_VERSION , check = false)
    private ChannelListRemoteService channelListRemoteService;
    @Reference(version = com.zmn.base.plat.engine.common.constant.DubboConsts.INTERFACE_VERSION , check = false)
    private ProductForeignListRemoteService productForeignListRemoteService;

    @Autowired
    private OrderWorkListBService orderWorkListBService;
    @Autowired
    private OrderWorkService orderWorkService;
    @Autowired
    private OrderMasterService orderMasterService;
    @Autowired
    private OrderDetailService orderDetailService;
    @Autowired
    private ZmnMQSender zmnMQSender;
    @Resource
    private OrderProductService orderProductService;

    /**
     * 呼叫信息录入
     *
     * @param callInfo
     * @return
     */
    @Override
    public ResultDTO insertCallInfo(CallInfo callInfo) {

        // 查询城市信息
        ResponseDTO<AreaDRO> cityResponseDTO = areaListRemoteService.getById(callInfo.getCityId());
        if (cityResponseDTO.getData() != null) {
            callInfo.setCityName(cityResponseDTO.getData().getName());

            // 查询省份信息
            ResponseDTO<AreaDRO> provinceResponseDTO = areaListRemoteService.getById(cityResponseDTO.getData().getParentId());
            if (provinceResponseDTO.getData() != null) {
                callInfo.setProvinceName(provinceResponseDTO.getData().getName());
                callInfo.setProvinceId(provinceResponseDTO.getData().getAreaId());
            }
        }

        // 查询区县信息
        if (callInfo.getCountyId() != null) {
            ResponseDTO<AreaDRO> countyResponseDTO = areaListRemoteService.getById(callInfo.getCountyId());
            if (countyResponseDTO.getData() != null) {
                callInfo.setProvinceName(countyResponseDTO.getData().getName());
                callInfo.setProvinceId(countyResponseDTO.getData().getAreaId());
            }
        }

        if (callInfo.getChannelId() != null) {
            ResponseDTO<ChannelDRO> channelDROResponseDTO = channelListRemoteService.getByChannelId(callInfo.getChannelId());
            if (channelDROResponseDTO.getData() != null) {
                callInfo.setChannelName(channelDROResponseDTO.getData().getName());
            }
        }

        // 产品
        if (callInfo.getProductId() != null) {
            ProductBaseQuery productDIO = new ProductBaseQuery();
            productDIO.setProductId(callInfo.getProductId());
            com.zmn.common.dto2.ResponseDTO<List<ProductBaseDRO>> productResponseDTO = productForeignListRemoteService.listBaseDROByQuery(productDIO);
            if (CollectionUtil.isNotNullOrEmpty(productResponseDTO.getData())) {
                callInfo.setProductName(productResponseDTO.getData().get(0).getProductName());
                callInfo.setServCategName(productResponseDTO.getData().get(0).getServCategName());
            }
        }

        String telephone = callInfo.getUserPhone();
        if (StringUtils.isNotBlank(telephone) && telephone.length() >= 4) {
            callInfo.setUserPhoneEnd4(telephone.substring(telephone.length() - 4));
        }

        //录入信息当天信息是否存在这个电话号码（当天指：00:00到现在的）-- >电话号码，录入时间
        OrderWorkQuery query = new OrderWorkQuery();
        query.setConcatPhone(telephone);
        query.setReceiveTime(DateUtil.dateFormatToString(new Date(), DateUtil.FORMAT_DEFAULT) + "," + DateUtil.dateFormatToString(new Date(), DateUtil.FORMAT_DATE));
        Integer count = orderWorkListBService.countOrderWorkByQuery(query);

        if (count > 0) {
            return ResultDTO.fail("此用户" + telephone + "今日已下单");
        }

        if (useNewInterface) {
            // 新接口
            return this.addCallOrder(callInfo);
        } else {
            // 老接口
            return this.addCallOrderOld(callInfo);
        }
    }

    /**
     *  新接口
     * @param callInfo
     * @return
     */
    private ResultDTO addCallOrder(CallInfo callInfo) {
        CallAddInfo callAddInfo = new CallAddInfo();
        StringJoiner sb = new StringJoiner(" ");
        if (StringUtils.isNotBlank(callInfo.getStreet())) {
            sb.add(callInfo.getStreet());
        }
        if (StringUtils.isNotBlank(callInfo.getAddress())) {
            sb.add(callInfo.getAddress());
        }
        callAddInfo.setAddress(sb.toString());
        callAddInfo.setChannelId(callInfo.getChannelId());
        callAddInfo.setProvinceId(callInfo.getProvinceId());
        callAddInfo.setProvinceName(callInfo.getProvinceName());
        callAddInfo.setCityId(callInfo.getCityId());
        callAddInfo.setCityName(callInfo.getCityName());
        callAddInfo.setClueCategory(callInfo.getProductName());
        callAddInfo.setCustomerName(callInfo.getUserName());
        callAddInfo.setCustomerNumber(callInfo.getUserPhone());
        callAddInfo.setOperator(callInfo.getCreater());
        // 自动外呼 1自动外呼，2手动外呼
        if (Objects.equals(1, callInfo.getAutomatic())) {
            callAddInfo.setOutRequire("AUTO_OUT");
        } else if (Objects.equals(2, callInfo.getAutomatic())) {
            callAddInfo.setOutRequire("NOT_AUTO_OUT");
        }
        callAddInfo.setRemark(callInfo.getRemark());
        callAddInfo.setSourceData(JSON.toJSONString(callInfo));
        if (NumberUtil.isNullOrZero(callInfo.getSourceType())) {
            callAddInfo.setSourceType("REN_GONG_LU_DAN");
        }

        try {
            Map<String, Object> body = Maps.newHashMap();
            Map<String, CallAddInfo> params = Maps.newHashMap();
            params.put("dio", callAddInfo);
            body.put("body", params);
            String json = JSON.toJSONString(body);

            log.info("#call#pop# 呼叫信息接口请求 {}, {}", CALL_INFO_URL, json);
            String res = MonitorHttpsUtils.postJson(CALL_INFO_URL, json);
            log.info("#call#pop# 呼叫信息接口响应 {}", res);

            if (StringUtil.isBlank(res)) {
                return ResultDTO.fail("失败");
            }

            ResponseDTO responseDTO = JSON.parseObject(res, new TypeReference<ResponseDTO>() {
            });

            if (responseDTO.getStatus() != null && Objects.equals(StatusConsts.ERROR_EXIST_MOBILE, responseDTO.getStatus())) {
                return ResultDTO.fail("此用户" + callInfo.getUserPhone() + "今日已在呼叫系统录入信息");
            }

            if (!responseDTO.isSuccess()) {
                String msg = StringUtils.isNotBlank(responseDTO.getMessage()) ? "录入失败-" + responseDTO.getMessage() : "录入失败";
                return ResultDTO.fail(msg);
            }

        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }

        return ResultDTO.success();
    }

    /**
     * 老接口
     * @param callInfo
     * @return
     */
    private ResultDTO addCallOrderOld(CallInfo callInfo){
        StringJoiner sb = new StringJoiner(" ");
        if (StringUtils.isNotBlank(callInfo.getStreet())) {
            sb.add(callInfo.getStreet());
        }
        if (StringUtils.isNotBlank(callInfo.getAddress())) {
            sb.add(callInfo.getAddress());
        }
        callInfo.setAddress(sb.toString());

        callInfo.setStreet(null);
        callInfo.setServCategName(null);

        Map<String, String> params = JSONObject.parseObject(JSON.toJSONString(callInfo), new TypeReference<Map<String, String>>() {
        });

        params.put("sign", MethodSignUtils.sign(params, SIGN_KEY));

        try {
            log.info("#call#pop# 呼叫信息接口请求 {}, {}", CALL_INFO_OLD_URL, JSON.toJSONString(params));
            String res = MonitorHttpsUtils.postForm(CALL_INFO_OLD_URL, params);
            log.info("#call#pop# 呼叫信息接口响应 {}", res);

            if (StringUtil.isBlank(res)) {
                return ResultDTO.fail("失败");
            }

            ResponseDTO responseDTO = JSON.parseObject(res, new TypeReference<ResponseDTO>() {
            });

            if (responseDTO.getStatus() != null && Objects.equals(StatusConsts.ERROR_EXIST_MOBILE, responseDTO.getStatus())) {
                return ResultDTO.fail("此用户" + callInfo.getUserPhone() + "今日已在呼叫系统录入信息");
            }

            if (!responseDTO.isSuccess()) {
                String msg = StringUtils.isNotBlank(responseDTO.getMessage()) ? "录入失败-" + responseDTO.getMessage() : "录入失败";
                return ResultDTO.fail(msg);
            }

        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }

        return ResultDTO.success();
    }


    /**
     * 催单外呼
     */
    @Override
    // @ZsNormalOrderWorkLog(type = OrderLogConsts.ORDER_LOG_TYPE_REMINDER, beforeProceed = false)
    public void callRemind(CallOutDTO callOutDTO) {
        Long orderId = callOutDTO.getOrderId();
        Long workId = callOutDTO.getWorkId();
        OrderWork orderWork = orderWorkService.findOrderWorkByKey(orderId, workId);
        List<OrderMaster> masters = orderMasterService.listMasterByWorkId(orderId, workId, OrderConsts.ORDER_MASTER_TYPE_MAIN);
        if (CollectionUtil.isNullOrEmpty(masters)) {
            return;
        }
        LoginStaff loginStaff = StaffAdminService.currentStaff();
        OrderMaster orderMaster = masters.get(0);

        CallInfoDTO callInfoDTO = new CallInfoDTO();
        callInfoDTO.setBizId(String.valueOf(workId));
        callInfoDTO.setOrderId(orderId);
        callInfoDTO.setPlat(orderWork.getPlat());
        callInfoDTO.setServicePlat(orderWork.getPlatWork());
        callInfoDTO.setAppKey("OMS");
        callInfoDTO.setRemindType(CallCenterConstant.REMINDER_SCENE); // 催单
        callInfoDTO.setTelPhone(orderMaster.getMasterPhone());
        callInfoDTO.setRealName(orderMaster.getMasterName());
        callInfoDTO.setLauncherStaffId(loginStaff.getStaffId());
        callInfoDTO.setLauncherStaffName(loginStaff.getRealName());
        this.callUrl(callInfoDTO);
    }

    /**
     * 派单超时外呼
     */
    @Override
    public void callDistributeTimeoutRemind(CallOutDTO callOutDTO) throws OmsBaseException {
        Long orderId = callOutDTO.getOrderId();
        Long workId = callOutDTO.getWorkId();
        OrderWork orderWork = orderWorkService.findOrderWorkByKey(orderId, workId);
        // 订单详情
        OrderDetail orderDetail = orderDetailService.findOrderDetailByKey(orderWork.getOrderId());

        String bizId = String.valueOf(workId);
        if (!useNewRemind) {
            CallInfoDTO callInfoDTO = new CallInfoDTO();
            callInfoDTO.setBizId(bizId);
            callInfoDTO.setOrderId(orderId);
            callInfoDTO.setPlat(orderWork.getPlat());
            callInfoDTO.setServicePlat(orderWork.getPlatWork());
            callInfoDTO.setAppKey("oms");
            callInfoDTO.setRemindType(CallCenterConstant.DISTRIBUTE_TIMEOUT_SCENE);
            callInfoDTO.setTelPhone(orderDetail.getTelephone());
            callInfoDTO.setRealName(orderDetail.getUserName());
            callInfoDTO.setLauncherStaffId(GlobalConsts.OPERATE_USER_TYPE_SYSTEM);
            callInfoDTO.setLauncherStaffName(GlobalConsts.getOperatorTypeName(GlobalConsts.OPERATE_USER_TYPE_SYSTEM));
            ResponseDTO<String> responseDTO = this.callUrl(callInfoDTO);
            if (!Objects.equals(responseDTO.getStatus(), StatusConsts.STATUS_SUCCESS)) {
                throw new OmsBaseException("派单超时外呼失败");
            }
            return;
        }
        RemindRequestDIO remindRequestDIO = new RemindRequestDIO();
        remindRequestDIO.setBizCallId(bizId);
        remindRequestDIO.setBizId(bizId);
        remindRequestDIO.setAppId(AppTypeEnum.OMS.getCode());
        remindRequestDIO.setScenesType(ScenesTypeEnum.NO_DISPATCHED_TIME_OUT.getCode());
        remindRequestDIO.setPhone(orderDetail.getTelephone());
        List<VoiceVariateDIO> variates = Lists.newArrayList();
        // 产品信息
        List<OrderProduct> orderProducts = orderProductService.listOrderProductByOrderId(orderId);
        if (CollectionUtil.isNullOrEmpty(orderProducts)) {
            return;
        }

        OrderProduct orderProduct = orderProducts.get(0);
        VoiceVariateDIO voiceVariateDIO = new VoiceVariateDIO();
        voiceVariateDIO.setVariateName("{$product_name}");
        voiceVariateDIO.setVariateText(StringUtil.isBlank(orderProduct.getShowProductName()) ? orderProduct.getProductName() : orderProduct.getShowProductName());
        variates.add(voiceVariateDIO);
        remindRequestDIO.setVariates(variates);

        remindRequestDIO.setExpireDuration(10 * 60);
        remindRequestDIO.setOperator("系统");
        String json = JSON.toJSONString(remindRequestDIO);
        log.info("派单超时外呼入参: topic={} data={}", MessageQueueTopicConstant.ZMN_TOPIC_REMIND, json);
        zmnMQSender.send(MessageQueueTopicConstant.ZMN_TOPIC_REMIND, MqConst.REMIND_REQUEST_TAG, bizId, json);
    }

    private ResponseDTO<String> callUrl(CallInfoDTO callInfoDTO) {
        Map<String, Object> map = new HashMap<>();
        map.put("data", JSON.parseObject(JSON.toJSONString(callInfoDTO)));
        String sign = SignUtil.sign(map, SIGN_KEY);
        map.put("sign", sign);
        log.info("{} 自动外呼request:[{}]", callInfoDTO.getBizId(), JSON.toJSONString(map));
        String response = null;
        try {
            response = MonitorHttpsUtils.postJson(CALL_REMIND_URL, JSON.toJSONString(map));
        } catch (Exception e) {
            log.error("{} 自动外呼error:[{}]", callInfoDTO.getBizId(), e.getMessage());
            return ResponseDTO.fail(e.getMessage());
        }
        log.info("{} 自动外呼reponse:[{}]", callInfoDTO.getBizId(), response);
        return JSON.parseObject(response, ResponseDTO.class);
    }

    /**
     * 呼叫线索录入
     * @param callClueInfo
     * @return
     */
    @Override
    public ResultDTO insertCallClue(CallClueInfo callClueInfo) {

        if (!useNewInterface) {
            // 老接口
            return this.insertCallClueOld(callClueInfo);
        }

        if (Objects.isNull(callClueInfo)) {
            return ResultDTO.fail("参数不能为NULL");
        }

        Map<String,Object>  bodyMap= new HashMap<>(1);
        Map<String,JSONObject>  paramsMap= new HashMap<>(1);
        JSONObject clueObject = new JSONObject();

        // 填充参数
        clueObject.put("channelId", callClueInfo.getChannelId());
        clueObject.put("channelName", callClueInfo.getChannelName());
        clueObject.put("customerNumber", callClueInfo.getCustomerPhone());
        clueObject.put("operator", StringUtils.defaultString(callClueInfo.getOperator(), GlobalConsts.getOperatorTypeName(GlobalConsts.OPERATE_USER_TYPE_SYSTEM)));

        if (StringUtil.isNotBlank(callClueInfo.getCustomerName())) {
            clueObject.put("customerName", callClueInfo.getCustomerName());
        }

        if (NumberUtil.isNotNullOrZero(callClueInfo.getCityId())) {
            clueObject.put("cityId", callClueInfo.getCityId());
        }

        if (StringUtil.isNotBlank(callClueInfo.getAddress())) {
            clueObject.put("address", callClueInfo.getAddress());
        }

        if (StringUtil.isNotBlank(callClueInfo.getRemark())) {
            clueObject.put("remark", callClueInfo.getRemark());
        }

        // 固定参数
        clueObject.put("sourceType","YI_LIAO");
        if (Objects.equals(callClueInfo.getAutomatic() , 1)) {
            clueObject.put("outRequire", "AUTO_OUT");
        } else {
            clueObject.put("outRequire", "NOT_AUTO_OUT");
        }

        paramsMap.put("dio", clueObject);
        bodyMap.put("body",paramsMap);

        try {
            log.info("#call#pop# 呼叫线索信息接口请求 {}, {}", CALL_INFO_URL, JSON.toJSONString(bodyMap));
            String res = MonitorHttpsUtils.postJson(CALL_INFO_URL, JSON.toJSONString(bodyMap));
            log.info("#call#pop# 呼叫线索信息接口返回 {}", res);

            if (StringUtil.isBlank(res)) {
                return ResultDTO.fail("失败");
            }

            ResponseDTO responseDTO = JSON.parseObject(res, new TypeReference<ResponseDTO>() {});

            if (!responseDTO.isSuccess()) {
                String msg = StringUtils.isNotBlank(responseDTO.getMessage()) ? "线索录入失败-" + responseDTO.getMessage() : "线索录入失败";
                return ResultDTO.fail(msg);
            }

        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }

        return ResultDTO.success();
    }

    /**
     * 呼叫线索录入 - 老接口
     * @param callClueInfo
     * @return
     */
    protected ResultDTO insertCallClueOld(CallClueInfo callClueInfo) {

        if (Objects.isNull(callClueInfo)) {
            return ResultDTO.fail("参数不能为NULL");
        }

        Map<String, String> params = new HashMap<>(3);

        if (NumberUtil.isNotNullOrZero(callClueInfo.getChannelId())) {
            params.put("channelId", String.valueOf(callClueInfo.getChannelId()));
        }

        params.put("channelName", Optional.ofNullable(callClueInfo.getChannelName()).orElse(""));
        params.put("userPhone", Optional.ofNullable(callClueInfo.getCustomerPhone()).orElse(""));
        params.put("remark", Optional.ofNullable(callClueInfo.getRemark()).orElse(""));

        if (NumberUtil.isNotNullOrZero(callClueInfo.getAutomatic())) {
            params.put("automatic", String.valueOf(callClueInfo.getAutomatic()));
        }

        params.put("sign", MethodSignUtils.sign(params, SIGN_KEY));

        try {
            log.info("#call#pop# 呼叫线索信息接口请求 {}, {}", CALL_CLUE_URL, JSON.toJSONString(params));
            String res = MonitorHttpsUtils.postForm(CALL_CLUE_URL, params);
            log.info("#call#pop# 呼叫线索信息接口返回 {}", res);

            if (StringUtil.isBlank(res)) {
                return ResultDTO.fail("失败");
            }

            ResponseDTO responseDTO = JSON.parseObject(res, new TypeReference<ResponseDTO>() {});

            if (!responseDTO.isSuccess()) {
                String msg = StringUtils.isNotBlank(responseDTO.getMessage()) ? "线索录入失败-" + responseDTO.getMessage() : "线索录入失败";
                return ResultDTO.fail(msg);
            }

        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }

        return ResultDTO.success();
    }
}
